package org.itboys.mobile.service.mongo.weixin;

import org.itboys.commons.ErrorException;
import org.itboys.commons.utils.tools.ListUtil;
import org.itboys.commons.utils.tools.LongUtil;
import org.itboys.mobile.common.SundayCommonConstants;
import org.itboys.mobile.entity.mongo.SundayLouKa;
import org.itboys.mongodb.core.MongoDataSource;
import org.itboys.mongodb.service.BaseMongoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Auther: 罗尧坤
 * Date: 2018/7/17
 * Description: 集楼_楼卡_小程序_service
 */

@Service
public class SundayWeiXinLouKaService extends BaseMongoService<SundayLouKa> {


    @Resource(name = "mobileDs")
    private MongoDataSource kitchenDataSource;
    @Override
    protected MongoDataSource getMongoDataSource() {
        return kitchenDataSource;
    }

    @Override
    protected Class<SundayLouKa> getEntityClass() {
        return SundayLouKa.class;
    }

    /**
     * 查询楼卡列表
     * @param request
     * @return
     */
    public List<SundayLouKa> selectLouka(HttpServletRequest request){
        Map<String, Object> param = new HashMap<>();
        param.put("isDeleted", 0);
        //倒序显示
        param.put("sort","ct");
        param.put("order","desc");
        List<SundayLouKa> result = super.list(param);
        return result;
    }

    /**
     * 查询出单个楼卡
     * @param id
     * @return
     */
    public SundayLouKa findOne(Long id){
        Map<String, Object> param = new HashMap<>();
        param.put("isDeleted", SundayCommonConstants.NO);
        param.put("id", id);

        //查出单个数据
        List<SundayLouKa> louKas =  super.list(param);
        if (ListUtil.isNotNull(louKas)){
            return louKas.get(0);
        }else {
            throw new ErrorException("数据丢失");
        }

    }

}
